# 通过调用 api实现通过学生名或者学号查询学生的所有信息
import requests
import sys
import io
import time
import json
import base64
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码

url = 'https://we.cqu.pt/api/get_student_info.php'

headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.44",
    "CONTENT_TYPE":"application/json"
}
# 信息替换点 
key = "刘锦源"
body = {"openid":"oIaII0RJSeox0VnG98Rg-Fd_DV5g","key":key,"page":1,"timestamp":time.time()}
# json格式 因为dist字典，map格式无法使用encode方法，，我们必须将这个转化为字符串
dataJson = json.dumps(body) 
# utf编码
utf8_data=dataJson.encode('utf-8')
# base64 加密
base64_data=base64.b64encode(utf8_data)
data = {"key":base64_data}


#在发送get请求时url + 请求头head + 请求体body
# 取消证书验证
resp = requests.post(url, headers = headers,data = data,verify=False)

# 打印返回的数据
print(resp.content.decode('utf-8'))

